package OT.shoufouni.serverThreads;


import OT.shoufouni.gpsMaps.russionMapExample;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;

public class serviceUpdateMyLocation extends Service{
		
	@Override
	    public void onCreate() {
	          super.onCreate();
	     
	          Context context = getApplicationContext();
	          SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
	          String user = prefs.getString("ID_MAIL", "");
	          serverUpdateLocation myLocationUpdate = new serverUpdateLocation(this.getApplication().getApplicationContext(),user, russionMapExample.getMyLocation());
	          myLocationUpdate.start();
	    }
 
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
    		
    	// make the thread start posting it position
    	Context context = getApplicationContext();
    	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor1 = prefs.edit();
        editor1.putBoolean("PUSH_LOCATION", true);
        editor1.commit();
        
        Log.d("serviceUpdateMyLocation ","service start running" +" id="+ Thread.currentThread().getId());
        return START_STICKY;
    }
    @Override
    public void onDestroy() {
          super.onDestroy();
          
       // make the thread stop posting it position
          Context context = getApplicationContext();
          SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
          Editor editor1 = prefs.edit();
          editor1.putBoolean("PUSH_LOCATION", false);
          editor1.commit();
          
          Log.d("serviceUpdateMyLocation ","service stop running" +" id="+ Thread.currentThread().getId());
    }
    
    @Override
    public IBinder onBind(Intent arg0) {
          return null;
    }

}
